import { createSlice } from "@reduxjs/toolkit";

interface IAppState {
    collapsed:boolean
}
// 使用localStorage将使用状态保存到本地
const initialState = {
    collapsed :localStorage.getItem('collapsed') == 'true'
} as IAppState

export const appSlice = createSlice({
    name:'app',
    initialState,
    reducers:{
        changeCollapsed(state){
            // 操作状态也保存到本地
            localStorage.setItem('collapsed',String(!state.collapsed))
            state.collapsed = !state.collapsed
        }
    }
})

export const { changeCollapsed } = appSlice.actions
export default appSlice.reducer
